<template>
  <div class="crm-page  home-page">
    <div>官方文档：<a href="https://micro-zoe.github.io/micro-app/" target="_blank">https://micro-zoe.github.io/micro-app/</a> </div>
    <div style="padding-top:30px">
      <el-button @click="getMenu">获取主菜单数据</el-button>
      <el-button @click="getUser">获取User信息</el-button>
      <el-button @click="getPerssion">获取权限信息</el-button>
      <el-button @click="getTokenStore">获取Token（主应用stroe）</el-button>
      <el-button @click="getTokenByCookie">获取Token（cookie）</el-button>
    </div>
    <div style="padding-top:10px">
      <el-input v-model="text" type="textarea" :rows="8" />
    </div>
    <div style="padding-top:10px">  <el-button @click="sendToMain">发送数据给主应用--打开Tab标签</el-button>  <el-button @click="sendLogout">发送数据给主应用--退出登录</el-button></div>

  </div>
</template>
<script>
import { getToken } from '@/utils/auth'

export default {
  name: 'Home',
  data() {
    return {
      text: ''
    }
  },
  methods: {
    getMenu() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        const data = window.microApp.getData()
        this.text = JSON.stringify(data.ROUTERS)
      }
    },
    getUser() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        const data = window.microApp.getData()
        this.text = JSON.stringify(data.USER)
      }
    },
    getPerssion() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        const data = window.microApp.getData()
        this.text = JSON.stringify(data.PERMISSONS)
      }
    },
    getTokenStore() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        const data = window.microApp.getData()
        this.text = data.token
      }
    },
    getTokenByCookie() {
      this.text = getToken()
    },

    sendToMain() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        window.microApp.dispatch({ event: 'openTag', data: { url: '/wb-crm/clue' }})
      }
    },
    sendLogout() {
      if (window.__MICRO_APP_ENVIRONMENT__ && window.microApp) {
        window.microApp.dispatch({ event: 'logout' })
      }
    }

  }
}
</script>
